﻿Imports FinanceiroDAL.ModuloConexao
Public Class PlanodeContasFRM
    Public op As Char
#Region "Itens"
    Private Sub rbativo_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbativo.CheckedChanged
        If rbativo.Checked = True Then
            gerarelatrio("Contas Ativas", "{Ofi_ClassCentroCusto.sta_codigo}=1")
        End If
    End Sub
    Private Sub rbinativo_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbinativo.CheckedChanged
        If rbinativo.Checked Then
            gerarelatrio("Contas Inativas", "{Ofi_ClassCentroCusto.sta_codigo}=2")
        End If

    End Sub
    Private Sub rbtodos_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbtodos.CheckedChanged
        If (rbtodos.Checked) Then
            gerarelatrio("Classificação Geral de Centro Custo", "")
        End If
    End Sub
    Private Sub RBEntradas_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBEntradas.CheckedChanged
        If RBEntradas.Checked Then
            gerarelatrio("Contas de Entrada", "{Gen_Grupos.gru_codigo}=1")
        End If
    End Sub

    Private Sub RBSaidas_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBSaidas.CheckedChanged
        If RBSaidas.Checked Then
            gerarelatrio("Contas de Saída", "{Gen_Grupos.gru_codigo}=2")
        End If
    End Sub
#End Region
#Region "Relatorio"
    Public Sub gerarelatrio(titulo As String, formula As String)
        Try
            Dim frm As New RelatoriosfinFRM
            Dim rpt As New PlanoContasREL
            Try
                rpt.SetDatabaseLogon(usuario, senha)
                rpt.SetParameterValue(0, titulo)
                rpt.RecordSelectionFormula = formula
                frm.CrystalReportViewer2.ShowGroupTreeButton = False
                frm.CrystalReportViewer2.ReportSource = rpt
                frm.ShowDialog()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
            frm.Dispose()
            rpt = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Finally

        End Try
    End Sub
#End Region
#Region "RBCentrocusto"
    Private Sub RBCentroCusto_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBCentroCusto.CheckedChanged
        Try
            Dim frm As New RelatoriosfinFRM
            Dim rpt As New CentroCustoREL
            Try
                rpt.SetDatabaseLogon(usuario, senha)
                rpt.SetParameterValue(0, "Relatório de Centro Custo")
                rpt.RecordSelectionFormula = ""
                frm.CrystalReportViewer2.ShowGroupTreeButton = False
                frm.CrystalReportViewer2.ReportSource = rpt
                frm.ShowDialog()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
            frm.Dispose()
            rpt = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Finally
        End Try
    End Sub
#End Region
#Region "Load"
    Private Sub PlanodeContasFRM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If op = "C" Then
            rbativo.Enabled = False
            RBEntradas.Enabled = False
            rbinativo.Enabled = False
            RBSaidas.Enabled = False
            rbtodos.Enabled = False
        End If
        If op <> "C" Then
            RBCentroCusto.Enabled = False
        End If
    End Sub
#End Region
End Class